package com.tdam2013.grupo07.networking;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class SendMessageHandler extends DefaultHandler {

	private SendMessageResponse response;
	
	public SendMessageResponse getResponse() 
	{
		return response;
	}

	@Override
	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException 
	{
		super.startElement(uri, localName, qName, attributes);
		if (qName.equalsIgnoreCase("RESULT"))
		{
			response=new SendMessageResponse();
			response.setSuccess(attributes.getValue(attributes.getIndex("type")).equalsIgnoreCase("success")?true:false);
			response.setId(attributes.getValue(attributes.getIndex("type")));
		}
		else if(qName.equalsIgnoreCase("DETAIL"))
		{
			response.setErrorCode(Integer.parseInt(attributes.getValue(attributes.getIndex("code"))));
			response.setErrorDescription(attributes.getValue(attributes.getIndex("description")));
		}
	}

	@Override
	public void characters(char[] ch, int start, int length) throws SAXException 
	{
		super.characters(ch, start, length);
	}
}
